package homwork;

import java.util.Scanner;
import java.util.TooManyListenersException;

public class Camel {
    public static void main(String[] args) {
        System.out.println("请输入一个驼峰名");
        Scanner scan = new Scanner(System.in);
        String str = scan.next();
        System.out.println("转为蛇形后：" + camelToSnake(str));
    }

    //驼峰名转蛇形名的方法
    public static String camelToSnake(String str) {
        String str2 = "";

        String[] str1 = str.split("");
        for (int i = 0; i < str1.length; i++) {
            if (i == 0) {
                continue;
            }
            char[] ch = str1[i].toCharArray();

            if (Character.isUpperCase(ch[0])) {
                str1[i] = "_" + str1[i];
            }
        }
        for (String items : str1) {
            str2 += items;

        }

        return str2.toLowerCase();
    }


}
